package org.example.bookshelf_manager.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @ClassName TimeRecordsAspect
 * @Description 时间 Aop
 * @Author ZJX
 * @Date 2024/9/2 15:16
 * @Version 1.0
 */

@Slf4j
@Component
@Aspect // 切面类
public class TimeRecordsAspect {

//    计算机中 advice 是 通知
//    切面 = 切点 + 通知

    @Around("execution(* org.example.bookshelf_manager.*.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        //记录开始时间
        long start = System.currentTimeMillis();
        //执行目标方法
        Object proceed = joinPoint.proceed();
        //记录结束时间
        long end = System.currentTimeMillis();
        //日志打印耗时
        log.info("耗时时间: "+ (end-start) + "ms");
        return proceed;
    }
}
